package com.tanhua.dubbo.api.mongo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.mongo.Voice;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Alfred
 * @Date: 2021/04/20/10:03
 * @Description:
 */
@Service
public class VoiceApiImpl implements VoiceApi{

    @Autowired
    private MongoTemplate mongoTemplate;
    /**
    * @Description: 桃花传音-保存语音
    * @Param: [voice]
    * @return: void
    * @Author: Alfred
    * @Date: 2021/4/20
    */
    @Override
    public void save(Voice voice) {
        voice.setId(ObjectId.get());//主键id
        voice.setCreated(System.currentTimeMillis());
        mongoTemplate.save(voice);
    }

    @Override
    public Voice getVoice() {
        Query query = new Query();
        query.with(Sort.by(Sort.Order.desc("created")));

        Voice voice = mongoTemplate.findOne(query,Voice.class);
        return voice;
    }
}
